package com.baoyang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baoyang.entity.ProductName;
import com.baoyang.entity.UnloadingPoint;
import com.baoyang.service.IUnloadingPointService;
import com.baoyang.tool.api.R;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 金佳军
 * @since 2025-08-08
 */
@RestController
@RequestMapping("/unloadingPoint")
public class UnloadingPointController {

    @Resource
    private IUnloadingPointService unloadingPointService;

    /**
     * 添加
     */
    @PostMapping("/add")
    public R add(@RequestBody UnloadingPoint unloadingPoint) {
        return R.status(unloadingPointService.save(unloadingPoint));
    }

    /**
     * 分页查询
     */
    @GetMapping("pageList")
    public R pageList(@RequestParam(defaultValue = "1") int pageNum,
                      @RequestParam(defaultValue = "10") int pageSize,
                      @RequestParam(required = false) String name) {
        Page<UnloadingPoint> page = new Page<>(pageNum, pageSize);
        IPage<UnloadingPoint> unloadingPointIPage = unloadingPointService.pageUserList(page, name);
        return R.data(unloadingPointIPage);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody UnloadingPoint unloadingPoint) {
        return R.status(unloadingPointService.updateById(unloadingPoint));
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id) {
        return R.status(unloadingPointService.removeById(id));
    }

    /**
     * 查询所有卸货地址列表
     */
    @GetMapping("/list")
    public R list() {
        return R.data(unloadingPointService.list());
    }

}
